package iamutkarshtiwari.github.io.ananas.editimage.adapter;

import iamutkarshtiwari.github.io.ananas.ResourceTable;
import ohos.agp.components.*;
import ohos.app.Context;
import ohos.global.resource.NotExistException;
import ohos.global.resource.WrongTypeException;

import java.io.IOException;

public class StickerTypeAdapter extends BaseItemProvider {
    private Context mContext;
    String[] stickerPathName = new String[6];
//    private int current = 0;
    Text text;

    public StickerTypeAdapter(Context context) {
        this.mContext = context;
        try {
            stickerPathName = mContext.getResourceManager().getElement(ResourceTable.Strarray_iamutkarshtiwari_github_io_ananas_type_names).getStringArray();
        } catch (IOException | NotExistException | WrongTypeException e) {
            e.printStackTrace();
        }
    }

    @Override
    public int getCount() {
        return 6;
    }

    @Override
    public Object getItem(int i) {
        return stickerPathName[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        final Component cpt;
        if (component == null) {
            cpt = LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_sticker_item, null, false);
        } else {
            cpt = component;
        }
        text = (Text) cpt.findComponentById(ResourceTable.Id_item);
        text.setText(stickerPathName[i]);
        return cpt;
    }
}
